DMelt:Programming/9 External libraries

From HandWiki
Member



External libraries

DataMelt can be used for dynamic download of external java libraries, as long as they are inside self-contained jar files. In the case of scripting languages, you can download a jar file and perform calculations in the same script using the class jhplot.Web jhplot.Web.

Here is an example how to use Michael Thomas Flanagan's Java Scientific Library [1] which cannot be shipped with DataMelt due to license restrictions:

# This example shows how to download a jar library,
# dynamically load it and execute a class from the downloaded library.
# The downloaded jar will be located in lib/user directory.
# Second execution will skip download

# Class to demonstrate the fourth order Runge-Kutta method in class RungeKutta.
# Michael Thomas Flanagan

from jhplot import Web
url="https://www.ee.ucl.ac.uk/~mflanaga/java/flanagan.jar"
print "Loading ",url
print Web.load(url)

from flanagan.math import ArrayMaths

# create an array
ar=ArrayMaths([10,28,2,3,4,4,5,6,6,7,88])
print "Index of minimum  is ", ar.minimumIndex()

This script download the self-contained flanagan.jar and individually uses it in the same script.

Note if you execute this script second time, this jar file will not be downloaded since it cached inside the disrectory "lib/usr" of the DatMelt installation.

If you are using DataMelt gui and you need to download some restricted libraries, call this command inside the BeanShell (button of the DatMelt GUI):

get_external()

it will download some external libraries. Then please restart DataMelt GUI.